package com.insurance.modules.claim.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.Query;

import com.insurance.modules.claim.dao.PolicyInfoDao;
import com.insurance.modules.claim.entity.PolicyInfoEntity;
import com.insurance.modules.claim.service.PolicyInfoService;


@Service("policyInfoService")
public class PolicyInfoServiceImpl extends ServiceImpl<PolicyInfoDao, PolicyInfoEntity> implements PolicyInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PolicyInfoEntity> page = this.page(
                new Query<PolicyInfoEntity>().getPage(params),
                new QueryWrapper<PolicyInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PolicyInfoEntity queryByPolicyNo(String policyNo) {
        LambdaQueryWrapper<PolicyInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(PolicyInfoEntity::getPolicyNo, policyNo);
        List<PolicyInfoEntity> list = this.list(lambdaQueryWrapper);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }

}